package org.wavetech.scrollingcascade;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

import org.wavetech.scrollingcascade.layout.Transferable;

public class LineView extends View implements Transferable {

    private final Paint paint;
    private float fraction;

    public LineView(Context context) {
        this(context, null);
    }

    public LineView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public LineView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        paint = new Paint();
        paint.setColor(0xeeF9F7FF);
    }


    @Override
    public void transition(float fraction) {
        this.fraction = fraction;
        invalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        float height = getHeight() * fraction;
        float left = 0;
        float top = 0;
        float right = getWidth();
        float bottom = height;

        canvas.drawRect(left, top, right, bottom, paint);
    }
}
